#pragma strict
import System.IO;
import System.Collections.Generic;
//////////////////////////////////////////////////////
///配置文件助手,读取文本,并处理Key=Value形式.
//////////////////////////////////////////////////////

class ConfigHelper{
	/** 读取一个字符式配置文件,返回Dictionary */
	static function Read(text:String):Dictionary.<String,String>{
		var dict:Dictionary.<String,String> = new Dictionary.<String,String>();
		if(String.IsNullOrEmpty(text))
			return dict;
		
		var sr:StringReader = new StringReader(text);
		while(true){
			var line:String = sr.ReadLine();
			if(line == null)
				break;
			if(line == "" || line.StartsWith("//"))
				continue;
			var items:String[] = line.Split("="[0]);
			var key:String = items[0].Trim();
			var value:String = items[1].Trim();
			dict.Add(key,value);
		}
		sr.Close();
		return dict;
	}
	
	/** 从Dictionary中根据key获取value */
	static function Get(dict:Dictionary.<String,String>,key:String):String{
		if(dict != null && !String.IsNullOrEmpty(key)){
			if(dict.ContainsKey(key))
				return dict[key];
		}
		return null;
	}
}